﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CompareForeignStructure.cs" company="">
//   
// </copyright>
// <summary>
//   The compare foreign structure.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

using DbDiff.Common.DataAccess;
using DbDiff.Common.Model;

namespace DbDiff.Common.Comparer
{
    using System;
    using Helper;

    /// <summary>
    /// The compare foreign structure.
    /// </summary>
    internal class CompareForeignStructure : CompareDataStructure
    {
        /// <summary>
        /// The compare structure field
        /// </summary>
        private readonly CompareForeignKeyStructure fld = null;

        /// <summary>
        /// Initializes a new instance of the <see cref="CompareForeignStructure"/> class.
        /// </summary>
        /// <param name="databaseCompare">
        /// The db compare.
        /// </param>
        /// <param name="objectType">
        /// The object type.
        /// </param>
        public CompareForeignStructure(DatabaseCompare databaseCompare, DatabaseObjectTypes objectType) : base(databaseCompare, objectType)
        {
            this.dv1Name = databaseCompare.DatabaseInfoBaseLeft.DatabaseDataSets.GetDataView(DatabaseDataSets.DtView.ForeignByTableName);
            this.dv1Key = databaseCompare.DatabaseInfoBaseLeft.DatabaseDataSets.GetDataView(DatabaseDataSets.DtView.ForeignByKey);
            this.dv2Name = databaseCompare.DatabaseInfoBaseRight.DatabaseDataSets.GetDataView(DatabaseDataSets.DtView.ForeignByTableName);
            this.dv2Key = databaseCompare.DatabaseInfoBaseRight.DatabaseDataSets.GetDataView(DatabaseDataSets.DtView.ForeignByKey);

            this.fld = new CompareForeignKeyStructure(databaseCompare, DatabaseObjectTypes.ForeignKey);
            this.rowColumnName = DataRowCompareIndex.Foreign;
        }

        /// <summary>
        /// The compare child rows.
        /// </summary>
        public override void CompareChildRows()
        {
            this.errorString += (this.errorString != string.Empty ? "," : string.Empty) +
                                this.fld.Compare(this.cmp.CurrentField);
        }
    }
}